package com.hdl.servlet.malltype;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hdl.entity.MallType;
import com.hdl.service.MallTypeService;
import com.hdl.service.impl.MallTypeServiceImpl;

/**
 * 异步请求获取商品分类集合
 * @author Administrator
 *
 */
@WebServlet("/type.let")
public class MallTypeListServlet extends HttpServlet{
	
	private MallTypeService service = new MallTypeServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//获取json字符串
		String json = service.findAllJson();
		//设置相应头
		resp.setContentType("application/json;charset=utf-8");
		//写回数据
		resp.getWriter().write(json);
		
//		List<MallType> list = service.findAll();
//		ObjectMapper mapper = new ObjectMapper();
//		mapper.writeValue(resp.getOutputStream(), list);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
